package xyz.labmem.main.modular.app.other.controller

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
import xyz.labmem.base.core.annotion.BusinessLog
import xyz.labmem.base.core.base.BaseVerify
import xyz.labmem.base.core.common.request.ComDelBatchReq
import xyz.labmem.base.core.common.response.ComAndColumnRes
import xyz.labmem.base.core.common.response.ComPageAndColumnRes
import xyz.labmem.base.core.enums.LogAnnotationOpTypeEnum
import xyz.labmem.base.core.result.RP
import xyz.labmem.base.core.result.RU
import xyz.labmem.base.core.result.RV
import xyz.labmem.base.core.tool.isNotBlank
import xyz.labmem.base.sys.base.BaseController
import xyz.labmem.base.sys.consts.PathPrefixConst
import xyz.labmem.main.modular.app.other.entity.AppOtherFunction
import xyz.labmem.main.modular.app.other.mapper.AppOtherFunction_Mapper
import xyz.labmem.main.modular.app.rmfk.entity.App_rfbrfssdyjdcjb
import xyz.labmem.main.modular.common.pojo.FormMap
import xyz.labmem.main.modular.common.pojo.FormPage
import xyz.labmem.main.modular.common.service.selectFormPage

@RestController
@Api(tags = ["常用功能"])
@RequestMapping("${PathPrefixConst.APP_PATH_PREFIX}appOtherFunction")
class AppOtherFunction_Controller (
    private var appotherfunctionMapper: AppOtherFunction_Mapper
) : BaseController() {

    @BusinessLog(title = "修改常用功能", opType = LogAnnotationOpTypeEnum.UPDATE)
    @PostMapping("insert")
    @ApiOperation(value = "保存常用功能")
    fun insert(@RequestBody req: AppOtherFunction): RV<*> {
        //删除
        var list1 = appotherfunctionMapper.selectList(QueryWrapper<AppOtherFunction>().apply { this.eq("order_id", req.orderId) })
        for(list in list1){
            list.orderId =200
            appotherfunctionMapper.updateById(list)
        }
        //修改
        return  resultJudgment(req.updateById())
    }

    @PostMapping("selectById")
    @ApiOperation(value = "根据主键常用功能")
    fun selectById(@RequestBody req: AppOtherFunction): RV<*> {
        return if (req.prefix.isNotBlank()) {
            success(req.selectById())
        } else
            failedMsg("prefix不能为空")
    }

    @PostMapping("selectByXid")
    @ApiOperation(value = "根据序号进行常用功能")
    fun selectByXid(@RequestBody req: AppOtherFunction): RV<*> {
        var queryWrapper = QueryWrapper<AppOtherFunction>().apply {
            if(req.orderId.toString().isNotBlank()){
                this.eq("order_id", req.orderId)
            }
            this.le("order_id",100)
            this.orderByAsc("order_id")
        }
        return success(appotherfunctionMapper.selectList(queryWrapper))
    }

    @DeleteMapping("delBatch")
    @ApiOperation(value = "批量删除常用功能")
    fun delBatch(@RequestBody @Validated req: ComDelBatchReq): RV<*> {
        for(id in req.ids){
            appotherfunctionMapper.updateById(AppOtherFunction().apply {
                this.prefix = id;this.orderId = 200
            })
        }

        return resultJudgment(req.ids.size, "删除成功！", "没有数据被删除")
    }

    @PostMapping("listAll")
    @ApiOperation(value = "下拉选框常用功能")
    fun mapDots(@RequestBody req: AppOtherFunction): RU {
        var queryWrapper = QueryWrapper<AppOtherFunction>().apply {
            if(req.prefix.isNotBlank()){
                this.like("prefix", req.prefix)
            }
            this.ge("order_id",100)
            this.orderByAsc("order_id")
        }
        return success(appotherfunctionMapper.selectList(queryWrapper))
    }
}